const { request } = require("../../request/index.js")

Page({
  data: {
    swiperList: [],
    categoryList: [],
    floor: []
  },
  // 页面开始加载就会触发
  onLoad: function () {
    // 发送异步请求获取轮播数据
    // wx.request({
    //   url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
    //   success: (result) => {
    //     console.log(result.data.message)
    //     this.setData({
    //       swiperList: result.data.message
    //     })
    //   }
    // }); 
    this.getSwiperList()
    this.getCategoryList()
    this.getFloorList()

  },
  // 获取轮播图数据
  getSwiperList: function () {
    request({url: '/home/swiperdata'})
    .then(result => {
      this.setData({
         swiperList: result.data.message
      })
    })
  },
  // 获取分类数据
  getCategoryList: function () {
    request({url: '/home/catitems'})
    .then(result => {
      this.setData({
        categoryList: result.data.message
      })
    })
  },
  getFloorList: function () {
    request({url: '/home/floordata'})
    .then(result => {
      console.log(result)
      this.setData({
        floorList: result.data.message
      })
    })
  }
})

